package com.ruoyi.service.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;


import com.ruoyi.common.core.domain.Ztree;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.domain.SysMatClassificationType;
import com.ruoyi.mapper.SysMatClassificationTypeMapper;
import com.ruoyi.mapper.SysMatDataTypeMapper;
import com.ruoyi.mapper.SysMatDetailsTypeMapper;
import com.ruoyi.utils.DictUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.mapper.SysMatTypeMapper;
import com.ruoyi.domain.SysMatType;
import com.ruoyi.service.ISysMatTypeService;
import com.ruoyi.common.core.text.Convert;

/**
 * 材料类型Service业务层处理
 * 
 * @author ruoyi
 * @date 2020-07-03
 */
@Service
public class SysMatTypeServiceImpl implements ISysMatTypeService 
{
    @Autowired
    private SysMatTypeMapper sysMatTypeMapper;
    @Autowired
    private SysMatClassificationTypeMapper selectDictDataByType;
    @Autowired
    private SysMatDataTypeMapper selectDictDataByTypeMapper;
    @Autowired
    private SysMatDetailsTypeMapper sysMatDetailsTypeMapper;

    /**
     * 查询材料类型
     * 
     * @param matId 材料类型ID
     * @return 材料类型
     */
    @Override
    public SysMatType selectSysMatTypeById(Integer matId)
    {
        return sysMatTypeMapper.selectSysMatTypeById(matId);
    }

    /**
     * 查询材料类型列表
     * 
     * @param sysMatType 材料类型
     * @return 材料类型
     */
    @Override
    public List<SysMatType> selectSysMatTypeList(SysMatType sysMatType)
    {
        return sysMatTypeMapper.selectSysMatTypeList(sysMatType);
    }

    /**
     * 新增材料类型
     * 
     * @param sysMatType 材料类型
     * @return 结果
     */
    @Override
    public int insertSysMatType(SysMatType sysMatType)
    {
        sysMatType.setMatCreateTime(new Date());
        return sysMatTypeMapper.insertSysMatType(sysMatType);
    }

    /**
     * 修改材料类型
     * 
     * @param sysMatType 材料类型
     * @return 结果
     */
    @Override
    public int updateSysMatType(SysMatType sysMatType)
    {
        sysMatType.setMatCreateTime(new Date());
        return sysMatTypeMapper.updateSysMatType(sysMatType);
    }

    /**
     * 删除材料类型对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteSysMatTypeByIds(String ids)
    {
        return sysMatTypeMapper.deleteSysMatTypeByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除材料类型信息
     * 
     * @param matId 材料类型ID
     * @return 结果
     */
    @Override
    public int deleteSysMatTypeById(Integer matId)
    {
        return sysMatTypeMapper.deleteSysMatTypeById(matId);
    }

    /**
     * 清空缓存数据
     */
    @Override
    public void clearCache() {
        DictUtils.clearDictCache();
    }

    /**
     * 查询字典类型树
     *
     * @param matType 字典类型
     * @return 所有字典类型
     */
    @Override
    public List<Ztree> selectDictTree(SysMatType matType) {
        List<Ztree> ztrees = new ArrayList<Ztree>();
        return ztrees;
    }

    /**
     * 查询集合
     * @param matType
     * @return
     */
    @Override
    public List<SysMatType> selectYC(String matType) {
        return sysMatTypeMapper.selectYC(matType);
    }


    /**
     * 查询材料类型对应的英文字符串
     * @param matclass
     * @return
     */
    @Override
    public String a(String matclass) {
        return sysMatTypeMapper.a(matclass);
    }

    /**
     * 根据字典类型查询字典数据
     *
     * @param matType 字典类型
     * @return 字典数据集合信息
     */
    @Override
    public List<SysMatClassificationType> selectSysMatTypeByType(String matType) {
        List<SysMatClassificationType> matTypes = DictUtils.getDictCache(matType);
        if (StringUtils.isNotNull(matTypes))
        {
            return matTypes;
        }
        matTypes = selectDictDataByType.selectSysMatTypeByType(matType);
        if (StringUtils.isNotNull(matTypes))
        {
            DictUtils.setDictCache(matType,matTypes);
            return matTypes;
        }
        return null;
    }

    public String transDictName(SysMatType dictType)
    {
        StringBuffer sb = new StringBuffer();
        sb.append("(" + dictType.getMatName() + ")");
        sb.append("&nbsp;&nbsp;&nbsp;" + dictType.getMatType());
        return sb.toString();
    }
}
